<template>


	<div class="iframebo">
		<button @click='goback()'>
			返回列表</button> <iframe id="frame" :src="url" frameborder="0"></iframe>
	</div>

</template>
<script>
	export default {

		data() {
			return {
				url: '',
				// 分类列表
				parm: [],
				reportUrl: null,
				designId:null,
			};
		},
		beforeDestory() {
			window.removeEventListener('message', this.listenerFun)
		},
		mounted() {
			// console.log(product_id,123456);
			this.Id();
			window.addEventListener('message', this.listenerFun)
		},
		methods: {
			listenerFun(e){
				console.log(this.designId)
				console.log(e,'222');
				console.log(e.data.easyDesignId,'111111');
					if(e.data.easyDesignId && this.designId){
						this.$http.post('/api/admin/designer/KuJiaLe/upeasy',{design_id:this.designId,easy_id:e.data.easyDesignId}).then((reg)=>{
							this.$message({
								showClose: true,
								message: '轻设计同步成功',
								type: "success"
							});
						});
					}
			},

			// 获取页面id
			Id() {
				console.log(this.$route.params);
				let thisparm = this.$route.params;

				switch (thisparm.gotype) {
					case 'toNew':
						this.$api.kjlDesignNew()
							.then(res => {
								console.log(res);
								if (res.code == 1) {
									this.url = res.data.url;
								} else {
									this.$message({
										showClose: true,
										message: res.msg,
										type: "error"
									});
								}
							}).catch(err => {
								this.$message({
									showClose: true,
									message: "网络错误",
									type: "error"
								});
							});

						break;
					case 'toPano':
						if (typeof thisparm.url != "undefined") {
							console.log(thisparm)
							this.url = thisparm.url;
							this.designId=thisparm.designId;
						} else {
							//this.$router.go(-1);
							this.$message({
								showClose: true,
								message: '该方案还没生成漫游图',
								type: "error"
							});
						}
						break;
					case 'toPlanEdit':
						if (typeof thisparm.planid != "undefined") {
							this.$api.kjlDesignEdit({
									plan_id: thisparm.planid
								})
								.then(res => {
									console.log(res);
									if (res.code == 1) {
										this.url = res.data.url;

									} else {
										this.$message({
											showClose: true,
											message: res.msg,
											type: "error"
										});
									}
								}).catch(err => {
									this.$message({
										showClose: true,
										message: "网络错误",
										type: "error"
									});
								});
						} else {
							this.$message({
								showClose: true,
								message: "参数错误",
								type: "error"
							});
							//this.$router.go(-1);
						}
						break;
					default:
						this.$message({
							showClose: true,
							message: "参数错误",
							type: "error"
						});
						//this.$router.go(-1);
				};


			},
			goback() {
				this.$router.go(-1);
			}

		},

	};
</script>

<style lang="less" scoped="scoped">
	@import "kjlOnePoint.less";
</style>
<style scoped="scoped">
	.iframebo {
		height: 100%;
	}

	iframe {
		width: 100%;
		height: 100%;
	}

	button {
		padding: 5px 10px;
		height: 60px;
		width: 120px;
		line-height: 60px;
		top: 0;
		left: 0;
		position: absolute;
	}
</style>
